package com.example.demo.service.people;


import com.example.demo.dao.people.EmployeeDAO;
import com.example.demo.model.people.Employee;
import com.example.demo.model.system.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployeeService {
    @Autowired
    private EmployeeDAO dao;

    public List<Employee> getByEmployeeDept(Integer employee_dept) {
        return dao.getByEmployeeDept(employee_dept);
    }

    public List<Employee> selectAll() {
        return dao.selectAll();
    }

    public Integer addEmployee(Employee employee) {
        return dao.addEmployee(employee);
    }

    public Integer deleteById(Integer employee_id) {
        return dao.deleteById(employee_id);
    }

    public Integer updateById(Employee employee) {
        return dao.updateById(employee);
    }

    public List<Employee> findEmployee(String employee_name, Integer employee_dept) {
        return dao.findEmployee(employee_name, employee_dept);
    }

    public Boolean save(Employee employee) {
        Boolean flag = false;

        if (employee.getEmployee_id() != null) {
            flag = dao.updateById(employee) == 1;
        } else {
            flag = dao.addEmployee(employee) == 1;
        }

        return flag;
    }
}
